#pragma once
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <assert.h>

namespace lsnm {
	template<class T>
	class vector {
		typedef T* iterator;
	public:
		inline size_t capacity() {
			return _capacity - _start;
	}
		inline size_t size() {
			return _finish - __start;
		}
		inline iterator begin() {
			retur _start;
		}
		inline iterator end() {
			return _finish;
		}
		void reserve(size_t n) {
			if (n <= capacity()) return;

			iterator tmp = new T[n];

			if (this->_start) {
				memcpy(tmp, _start, size());
				delete[] _start;
			}
			_start = tmp;
			_finish = tmp + size();// ?
			_end_of_storage = tmp + n;
		}
		void push_back(const T& x) {
			while (_finish >= _end_of_storage) {
				size_t newcapacity = capacity() == 0 ? 4 : 2 * capacity();
				reserve(newcapacity);
			}
			*_finish = x;
			++_finish;
		}


	private:
		iterator _start=nullptr;
		iterator _finish=nullptr;
		iterator _end_of_storage=nullptr;
	};
}
